﻿using System;
using Nexia.FluentHtmlElements.Utilities;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;

namespace FluentHtmlElements.Tests.Elements
{
	[TestFixture]
	public class ElementTestBase : BaseFixture
	{
		protected void TestStringAttribute_SetAttrIsCalled_Helper(Action<ElementBaseTestSubject, string> expectedCall, Func<ElementBaseTestSubject, string, ElementBaseTestSubject> methodUnderTest, string value)
		{
			var tagBuilder = Stub<ITagBuilder>();

			var elementBase = Partial<ElementBaseTestSubject>(tagBuilder);
			expectedCall(elementBase, value);

			ReplayAll();

			methodUnderTest(elementBase, value);

			VerifyAll();
		}

		protected void TestStringAttribute_AnyCall_ReturnsSelf<T>(Func<ElementBaseTestSubject, T, ElementBaseTestSubject> methodUnderTest)
		{
			var tagBuilder = Stub<ITagBuilder>();

			var elementBase = new ElementBaseTestSubject(tagBuilder);

			ReplayAll();

			var returnValue = methodUnderTest(elementBase, default(T));

			Assert.That(returnValue, Is.SameAs(elementBase));

			VerifyAll();
		}

		/// <summary>
		/// A stub who's ToString value can be set through a property.
		/// </summary>
		/// <remarks>This object is used because Rhino mocks doesn't seem to be able to do it.</remarks>
		protected class StubObject
		{
			public string ToStringValue;

			public override string ToString()
			{
				return ToStringValue;
			}
		}
	}
}
